<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
    
      <el-form-item label="联系人" prop="contacts">
        <el-input
          v-model="queryParams.contacts"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['approval:information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['approval:information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['approval:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['approval:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" :index="createIndex" />
      <el-table-column label="标题" align="center" prop="title"  :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span @click="viewContent(scope.row)">{{scope.row.title}}</span>
        </template>
      </el-table-column>
      <el-table-column label="浏览次数" align="center" prop="browseNumber" />
      <el-table-column label="点赞人数" align="center" prop="giveNumber" />
      <el-table-column label="收藏人数" align="center" prop="collectNumber" />
      <el-table-column label="审批人" align="center" prop="realName" />
      <el-table-column label="审批状态" align="center" prop="checkStatus" :show-overflow-tooltip="true">
      <template slot-scope="scope">
       <el-row :gutter="10"  v-if="scope.row.checkStatus==2">
        <el-col :span="12" :lg="12">
          <dict-tag :options="dict.type.sys_audit_status" :value="scope.row.checkStatus"/>
        </el-col>
         <el-col :span="12" :pull="3" >
        <div class="grid-content bg-purple-light">{{scope.row.rejectReason}}</div>
        </el-col>
      </el-row>
      <el-row v-else :gutter="20">
        <dict-tag :options="dict.type.sys_audit_status" :value="scope.row.checkStatus"/>
      </el-row>
      </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="publishTime" width="180">
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
            <template slot-scope="scope">
          <el-switch  v-model="scope.row.status"
                active-value="0"
                inactive-value="2"
                @change="handleStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['approval:information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['approval:information:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资讯对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="文章链接">
          <el-col :span="18" :xs="24">
          <el-input type="text"  v-model="input" clearable placeholder="请输入文章链接" ref="conten_val"></el-input >
          </el-col>
          <el-col :span="6" :xs="24">
          <el-button type="primary" icon="el-icon-chat-dot-round" round @click="getContent(form)">导入</el-button>
          </el-col>
        </el-form-item>
        <el-form-item label="资讯标题" prop="title">
          <el-input v-model="form.title" type="text" placeholder="请输入内容" />
        </el-form-item>
       
        <el-form-item label="资讯标签" prop="tags">
          <el-input v-model="form.tags" type="text" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="资讯封面" prop="pcUrl">
          <el-upload
          class="avatar-uploader"
          ref="upload"
          :action="upload.url"
          :headers="upload.headers"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" style="width:100px;height:100px;">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        </el-form-item>
        <el-form-item label="联系人" prop="contacts">
          <el-input v-model="form.contacts" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="联系地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入联系地址" />
        </el-form-item>
         <el-form-item label="发布时间" prop="publishTime">
          <el-date-picker clearable
            v-model="form.publishTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发布时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="浏览次数" prop="browseNumber">
          <el-input v-model="form.browseNumber" placeholder="请输入浏览次数" />
        </el-form-item>
        <el-form-item label="点赞人数" prop="giveNumber">
          <el-input v-model="form.giveNumber" placeholder="请输入点赞人数" />
        </el-form-item>
        <el-form-item label="收藏人数" prop="collectNumber">
          <el-input v-model="form.collectNumber" placeholder="请输入收藏人数" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
      
       <el-form-item label="内容">
         <div class="divList">
            <div class="scrollbar_wrap">
          <editor v-model="form.content" :min-height="710"/>
            </div>
          </div>
        </el-form-item>
       
        </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--查看具体内容-->
    <el-dialog :title="title" :visible.sync="contentOpen" width="70%" append-to-body>
      <el-form ref="viewForm" :model="viewForm" :rules="rules" label-width="80px">
       
        <el-card shadow="always"   class="box_card"  style="">
               {{viewForm.title}}
        </el-card>
    
        <el-carousel :interval="4000" type="card" height="600px" width="400px">
        <el-carousel-item v-for="item in viewForm.pcUrlList" :key="item">
          <img :src="item" alt="" class="medium" width="700px" height="700px">
     
        </el-carousel-item>
        </el-carousel>
          <el-card shadow="always" class="boxCrad">
               发布人:&nbsp;{{viewForm.contacts}}
        </el-card>
          <el-card shadow="always" style="font-weight:bold;">
              联系方式:&nbsp;{{viewForm.phone}},{{form.viewForm}}
        </el-card>
          <div class="condiv">
             <span v-html='viewForm.content'></span>
          </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInformation, getInformation, delInformation, addInformation, updateInformation,changeNoticeStatus } from "@/api/approval/information";
import { getToken } from "@/utils/auth";
export default {
  name: "Information",
  dicts: ['sys_audit_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资讯表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      input:'',
      // 是否显示弹出层
      open: false,
      contentOpen:false,
       //上传参数
      upload:{
          // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/content/press/importData"
      },
       imageUrl: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        asId: null,
        title: null,
        content: null,
        tags: null,
        pcUrl: null,
        creatorId: null,
        contacts: null,
        phone: null,
        address: null,
        browseNumber: null,
        giveNumber: null,
        collectNumber: null,
        approverId: null,
        checkStatus: null,
        rejectReason: null,
        copyId: null,
        publishTime: null,
        status: null
      },
      viewForm:{
        id: null,
        asId: null,
        title: null,
        content: null,
        pcUrl: null,
        rejectReason: null,
        contacts: null,
        phone: null,
        pcUrlList:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        asId: [
          { required: true, message: "协会id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    createIndex(index){
      return (this.queryParams.pageNum-1)*(this.queryParams.pageSize)+index+1;
    },
    /** 查询资讯列表 */
    getList() {
      this.loading = true;
      listInformation(this.queryParams).then(res => {
        console.info(res);
        this.informationList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    //查看咨询详情
    viewContent(data){
      console.info(data);
      this.viewForm=data;
      this.contentOpen=true;
      this.title="查看内容"
    },
    //根据url获取文章内容
    getContent(form){
    console.info(this.$refs.conten_val.value);
     console.info(form.id); 
    },
     // 状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.id + '"公告吗？').then(function() {
        return changeNoticeStatus(row.id, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "2" : "0";
      });
    },
    //上传图片
     handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
           if(res.code==200){
          this.form.pcUrl=res.data;
        }else{
          console.info(res.msg)
        }
      },
  
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        asId: null,
        title: null,
        content: null,
        tags: null,
        pcUrl: null,
        creatorId: null,
        contacts: null,
        phone: null,
        address: null,
        browseNumber: null,
        giveNumber: null,
        collectNumber: null,
        approverId: null,
        checkStatus: 0,
        rejectReason: null,
        copyId: null,
        publishTime: null,
        createTime: null,
        updateTime: null,
        status: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资讯";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInformation(id).then(response => {
        console.info(response);
        this.form = response.data;
        this.imageUrl=response.data.pcUrl;
        this.open = true;
        this.title = "修改资讯";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资讯编号为"' + ids + '"的数据项？').then(function() {
        return delInformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('approval/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style >

.divList{
  border-style: solid;
  border-width: 1px;
  height:710px;
 
}
.scrollbar_wrap{
  height: 100%;
  overflow-x: hidden;
}
.display-scrollbar_thumb{
  background: transparent;
}

 .el-tooltip__popper{
    max-width:20%;
  }
  .el-tooltip__popper,.el-tooltip__popper.is-dark{
    background:rgb(27, 100, 190) !important;
    color: #fff !important;
    line-height: 20px;
    font-size: 15px;
  }

  .fromDiv{
    height: 800px;
    overflow: auto;
  }

   .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  .condiv{
  height: auto;  
  padding-left:10px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)
}
.boxCrad{
  font-weight:bold;
  margin-bottom: 10px;
  margin-top: 10px;
}
.el-carousel__item img {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    margin: 0;

  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  .box_card{
    margin-top: 10px;
    margin-bottom: 10px;
    height: auto;
    text-align: center;
    font-weight:bold;
    line-height: 14px;
  }
</style>


